package com.yizn.learn.springext.getspringcontex.ApplicationListener;

import com.yizn.learn.springext.getspringcontex.BeanFactoryAware.Person;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Service;

/**
 * project : my-learn
 * <p> 2.3 ApplicationListener接口 </p>
 *
 * @author yisl
 * @date 2023-01-13【星期五】
 **/
@Service
public class PersonService3 implements ApplicationListener<ContextRefreshedEvent> {
    private ApplicationContext applicationContext;
    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        this.applicationContext = event.getApplicationContext();
    }

    public void add(){
        Person person = (Person) this.applicationContext.getBean("person");
        person.test2();
    }
}
